package com.gxa.service.impl;

import com.gxa.mapper.EmployeeMapper;
import com.gxa.mapper.RoleMapper;
import com.gxa.pojo.Employee;
import com.gxa.pojo.PowerMenu;
import com.gxa.pojo.Role;
import com.gxa.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * (Employee)表服务实现类
 *
 * @author makejava
 * @since 2020-10-28 20:39:32
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired(required = false)
    private EmployeeMapper employeeMapper;
    @Autowired(required = false)
    private RoleMapper roleMapper;

    @Override
    public Employee findByEmployeeUsername(String employeeUsername) {
        Employee employee=employeeMapper.findByEmployeeUsername(employeeUsername);
        List<Role> rolesList = roleMapper.findRoleByEmployee(employee.getEmployeeId());
        List<Integer> listRoleId = new ArrayList<>();
        for (Role role : rolesList) {
            listRoleId.add(role.getRoleId());
        }
        List<PowerMenu> powerMenuList = roleMapper.findPowerMenuByRoleId(listRoleId);
        employee.setRoleList(rolesList);
        employee.setPowerMenuList(powerMenuList);
        return employee;
    }

    @Override
    public int updateEmployeePwd(String employeePwd, String employeeUsername) {
        return employeeMapper.updateEmployeePwd(employeePwd,employeeUsername);
    }
}